<?php

/**
 * Description of database
 *
 * @author user
 */
class Database {

    private static $db_config;
    private static $db_handler;

    public function __construct() {
        
    }

    public function __clone() {
        trigger_error('Clone is not allowed', E_USER_ERROR);
    }

    public static function &handler() {
        if (!isset(self::$db_handler)) {
            self::connect();
        }

        return self::$db_handler;
    }

    private static function connect() {
        require_once BASEPATH . '/config/database.php';

        self::$db_config = $db[$active_group];
        self::$db_handler = @mysql_connect(self::$db_config['hostname'],
                        self::$db_config['username'], self::$db_config['password']);

        if (self::$db_handler != 0) {
            if (mysql_select_db(self::$db_config['database'], self::$db_handler)) {
                return TRUE;
            }
        }

        return FALSE;
    }

    private static function disconnect() {
        return (@mysql_close(self::$db_handler) != 0) ? TRUE : FALSE;
    }

}

?>
